In [2]:
import graphlab
In [3]:
song_data = graphlab.SFrame('song_data.gl/')
In [4]:
song_data.head(5)
Out[4]:
In [5]:
graphlab.canvas.set_target('ipynb')
In [6]:
song_data['song'].show()
In [7]:
len(song_data)
Out[7]:
In [8]:
users = song_data['user_id'].unique()
In [10]:
len(users)
Out[10]:
In [11]:
train_data,test_data = song_data.random_split(.8,seed=0)
In [12]:
popularity_model = graphlab.popularity_recommender.create(train_data,
user_id='user_id',
item_id='song')
In [13]:
popularity_model.recommend(users=[users[0]])
Out[13]:
In [14]:
popularity_model.recommend(users=[users[1]])
Out[14]:
In [15]:
personalized_model = graphlab.item_similarity_recommender.create(train_data,
user_id='user_id',
item_id='song')
In [16]:
personalized_model.recommend(users=[users[0]])
Out[16]:
In [17]:
personalized_model.recommend(users=[users[1]])
Out[17]:
In [18]:
personalized_model.get_similar_items(['With Or Without You - U2'])
Out[18]:
In [19]:
personalized_model.get_similar_items(['Chan Chan (Live) - Buena Vista Social Club'])
Out[19]:
In [20]:
if graphlab.version[:3] >= "1.6":
model_performance = graphlab.compare(test_data, [popularity_model, personalized_model], user_sample=0.05)
graphlab.show_comparison(model_performance,[popularity_model, personalized_model])
else:
%matplotlib inline
model_performance = graphlab.recommender.util.compare_models(test_data, [popularity_model, personalized_model], user_sample=.05)